﻿namespace SsisLdapSource.DirectoryServicesProtocolsExtensions
{
    public partial class LdapMetaMapFactory
    {
        private readonly LdapMetaMapFactoryInitializationValues initializationValues;
        
        public LdapMetaMapFactory(LdapMetaMapFactoryInitializationValues initializationValues)

        {
            this.initializationValues = initializationValues;
        }
        
        public LdapAttributeMetaMap Create(string attributeDisplayName, string attributeSyntax, bool isMultiValued)
        {
            var metaMap = new LdapAttributeMetaMap(attributeDisplayName, isMultiValued);

            if (isMultiValued && 
                initializationValues.AttributesWhichMayRequireExpansion.Contains(attributeDisplayName))
            {
                metaMap.ExpansionMayBeRequired = true;
            }

            metaMap.RawDotNetTypeEquivalent = LdapTypeToRowDotNetTypeMapper.GetRawDotNetType(attributeSyntax);

            if (DoesAttributeValueHasDifferentSemanticMeaning(attributeDisplayName, attributeSyntax))
            {
                metaMap.SemanticDotNetTypeEquivalent =
                    GetDotNetSemanticType(attributeDisplayName, attributeSyntax);
                metaMap.SemanticValueConversionFunction =
                    GetDotNetSemanticConverter(attributeDisplayName, attributeSyntax);
            }

            return metaMap;
        }
    }
}
